package com.ruoyi.mall.front.service.impl;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.security.Md5Utils;
import com.ruoyi.mall.entity.MallMembers;
import com.ruoyi.mall.front.service.FrontLoginService;
import com.ruoyi.mall.mapper.MallMembersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName FrontLoginServiceImpl
 * @Description: TODO
 * @Author cjc
 * @Date 2020/5/15
 * @Version V1.0
 **/
@Service
public class FrontLoginServiceImpl implements FrontLoginService {
    /**
     *
     */
    @Autowired
    private MallMembersMapper mallMembersMapper;
    /**
     * 登录
     * @param mallMembers
     * @return
     */
    @Override
    public AjaxResult login(MallMembers mallMembers) {

        MallMembers mallMember = mallMembersMapper.selectMallMembersByPhone(mallMembers.getPhone());
        if(null == mallMember){
            return  AjaxResult.error("没有该用户或手机号输入有误！");
        }
        String hashPassword = Md5Utils.hash(mallMembers.getPassword());
        if(!hashPassword.equals(mallMember.getPassword())){
            return  AjaxResult.error("密码出错！");
        }


        return AjaxResult.success(mallMember);
    }
}
